import React, {Component,PureComponent} from 'react';
import "./index.css"
export default class Parent extends PureComponent {
    state = {
        carName:'奔驰c63'
    }



    change = ()=>{
        this.setState({carName:'宝马车'})
    }

    // shouldComponentUpdate(nextProps, nextState) {
    //     console.log(nextProps,nextState) // 接下来要变化的目标props和state
    //     console.log(this.props,this.state) // 目前的props和state
    //
    //     return !this.state.carName === nextState.carName
    //
    // }


    render() {
        console.log('parent_render')
        return (
            <div className="parent">
                <h3>我是parent组件</h3>
                <h4>我的车是:{this.state.carName}</h4>
                <button onClick={this.change}>点我换车</button>
                <Child carname="奥迪"/>
            </div>
        );
    }
}

class Child extends PureComponent{
    // shouldComponentUpdate(nextProps, nextState) {
    //     console.log(this.props,nextProps)
    //     return !this.props.carname === nextProps.carname
    // }

    render() {
        console.log('child_render')
        return (
            <div className="child">
                <h3>我是child组件</h3>
                <h4>我接到的车是:{this.props.carname}</h4>
            </div>
        );
    }
}


